package com.moss.cloud.plugins.biz.controller;
import com.moss.cloud.common.core.constant.ServiceList;
import com.moss.cloud.common.core.model.Result;
import com.moss.cloud.common.security.annotation.SysLog;
import com.moss.cloud.plugins.api.model.from.BaseFrom;
import com.moss.cloud.plugins.api.model.from.CodeTemplateFrom;
import com.moss.cloud.plugins.api.model.param.CodeTemplateParam;
import com.moss.cloud.plugins.biz.service.ICodeTemplateService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
* 代码模板配置前端控制器
*
* @author 瑾年
* @date 2024-01-08
*/
@RestController
@RequestMapping(ServiceList.PLUGINS + "/codeTemplate")
public class CodeTemplateController {

    private final ICodeTemplateService codeTemplateService;

    public CodeTemplateController(ICodeTemplateService codeTemplateService) {
        this.codeTemplateService = codeTemplateService;
    }

    /**
    * 分页查询
    *
    * @param param
    * @return
    */
    @PostMapping("/page")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_PLUGINS, operation = "分页查询")
    public Result<?> page(@RequestBody @Validated CodeTemplateParam param) {
        return Result.success(codeTemplateService.page(param));
    }

    /**
    * 新增
    *
    * @param from
    * @return
    */
    @PostMapping("/save")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_PLUGINS, operation = "新增代码模板配置")
    public Result<?> save(@RequestBody @Validated CodeTemplateFrom from) {
        return Result.success(codeTemplateService.save(from));
    }

    /**
    * 更新
    *
    * @param from
    * @return
    */
    @PostMapping("/update")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_PLUGINS, operation = "更新代码模板配置")
    public Result<?> update(@RequestBody @Validated CodeTemplateFrom from) {
        return Result.success(codeTemplateService.update(from));
    }

    /**
    * 删除
    *
    * @param baseFrom
    * @return
    */
    @PostMapping("/remove")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_PLUGINS, operation = "删除代码模板配置")
    public Result<?> remove(@RequestBody @Validated BaseFrom baseFrom) {
        return Result.success(codeTemplateService.remove(baseFrom));
    }

    /**
    * 详情
    *
    * @param baseFrom
    * @return
    */
    @PostMapping("/detail")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_PLUGINS, operation = "代码模板配置详情")
    public Result<?> detail(@RequestBody @Validated BaseFrom baseFrom) {
        return Result.success(codeTemplateService.detail(baseFrom));
    }

}
